package me.idashu.attg.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import me.idashu.attg.domain.GroupEntity;
import me.idashu.attg.domain.RoleEntity;
import me.idashu.attg.domain.UserEntity;
import me.idashu.attg.persistence.UserMapper;
import me.idashu.attg.util.MD5Encode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;

	public UserEntity getUser(UserEntity user) {

		String encodePass = MD5Encode.Md5(user.getPassword());
		user.setPassword(encodePass);
		return userMapper.getUser(user);
	}

	public List<UserEntity> getAllShop() {

		return userMapper.getAllShop();
	}

	public int getCountByEmail(String email) {
		int count = userMapper.getCountByEmail(email);
		return count;
	}

	public List<UserEntity> getUerEntityByPage(Map<String, Object> map) {
		List<UserEntity> listUser = userMapper.getUerEntityByPage(map);
		return listUser;
	}

	public int getCountAllUserEntity(UserEntity userEntity) {
		int count = userMapper.getCountAllUserEntity(userEntity);
		return count;
	}

	public void deleteUserEntity(int userId) {
		userMapper.deleteUserEntity(userId);
	}

	public void updateUserStatus(UserEntity userEntity) {
		userMapper.updateUserStatus(userEntity);
	}

	public int userLevelCount() {
		return userMapper.userLevelCount();
	}

	public List<RoleEntity> userLevelList(Map<String, Object> map) {
		return userMapper.userLevelList(map);
	}

	public void deleteUserLevel(int roleId) {
		userMapper.deleteUserLevel(roleId);
	}

	public List<GroupEntity> getAllGroup() {
		return userMapper.getAllGroup();
	}

	public int getCountByRoleName(String rolename) {
		return userMapper.getCountByRoleName(rolename);
	}

	public void addUserLevelInfo(RoleEntity roleEntity) {
		userMapper.addUserLevelInfo(roleEntity);
	}

	public RoleEntity getRole(int roleId) {
		return userMapper.getRole(roleId);
	}

	public void updateUserLevelInfo(RoleEntity roleEntity) {
		userMapper.updateUserLevelInfo(roleEntity);
	}

	public UserEntity findOneUserById(long id) {
		UserEntity user = userMapper.findOneUserById(id);
		return user;
	}

	public void updatePasswordById(UserEntity userEntity) {
		String encodePass = MD5Encode.Md5(userEntity.getPassword());
		userEntity.setPassword(encodePass);
		userMapper.updatePasswordById(userEntity);
	}

	public void register(UserEntity userEntity) {
		String encodePass = MD5Encode.Md5(userEntity.getPassword());
		userEntity.setPassword(encodePass);
		userEntity.setTime(new Date());
		userMapper.register(userEntity);
	}

	public List<UserEntity> searchUsers(Map<String, Object> map) {
		List<UserEntity> users = userMapper.searchUsers(map);
		return users;
	}
	
	public int searchCountUsers(UserEntity userEntity){
		int count = userMapper.searchCountUsers(userEntity);
		return count;
	}
	
	public void updateSetAttenById(UserEntity userEntity){
		userMapper.updateSetAttenById(userEntity);
	}
	
	public int userCount(){
		return userMapper.userCount();
	}
	
	public List<UserEntity> userList(Map<String, Object> map){
		return userMapper.userList(map);
	}
	
	public void forbiddenUser(int user_id){
		userMapper.forbiddenUser(user_id);
	}
	
	public List<UserEntity> partUserList(Map<String, Object> map){
		return userMapper.partUserList(map);
	}
	
	public void visitorToMember(UserEntity userEntity){
		String encodePass = MD5Encode.Md5(userEntity.getPassword());
		userEntity.setPassword(encodePass);
		userEntity.setTime(new Date());
		userMapper.visitorToMember(userEntity);
	}
	
	public int insertUserEntityYouKe(UserEntity userEntity){
		int userId = userMapper.insertUserEntityYouKe(userEntity);
		return userId;
	}
	
	public void updateUserEntityLocation(UserEntity userEntity){
		userMapper.updateUserEntityLocation(userEntity);
	}
}
